package com.gitee.wsl.mathematics.geometry.d3.vertex

import com.gitee.wsl.api.Id
import com.gitee.wsl.io.dataproxy.DataProxy
import com.gitee.wsl.io.dataproxy.asProxy
import com.gitee.wsl.mathematics.coordinate.d3.Coordinate3D
import com.gitee.wsl.mathematics.coordinate.d3.MutableCoordinate3D
import com.gitee.wsl.mathematics.geometry.d3.edge.Edge
import com.gitee.wsl.mathematics.vector.vec2.MutableVec2
import com.gitee.wsl.mathematics.vector.vec3.MutableVec3
import com.gitee.wsl.mathematics.vector.vec3.Vec3
import com.gitee.wsl.mathematics.vector.vec3.Vector3D
import com.gitee.wsl.mathematics.vector.vec4.MutableVector4


interface Vertex : Id, Coordinate3D<Vertex> {
    val kind: VertexKind
    val directedEdges: List<Edge> // edges are properly ordered clockwise
}

class MutableVertex(
    override val id: Int,
    pt: Vector3D<*>,
    override var kind: VertexKind,
    override val directedEdges: MutableList<Edge> = ArrayList(), // edges are properly ordered clockwise
    override val proxy: DataProxy<Double> = pt.valueArray.toDoubleArray().asProxy()
) : Vertex, MutableCoordinate3D<Vertex>, MutableKind<VertexKind> {

    override val self get() = this

    override val vec4: MutableVector4<Double, *>
        get() = TODO("Not yet implemented")

    override fun createVec2(a: Double, b: Double) = MutableVec2(a,b)

    override fun create(x: Double, y: Double, z: Double): MutableVertex = MutableVertex(
        id, Vec3(x, y, z),
        kind = kind,
    )

    override fun equals(other: Any?): Boolean = other is Vertex && id == other.id
    override fun hashCode(): Int = id
    override fun toString(): String = "$kind vertex(id=$id, ${super.toString()})"

}

//fun Vertex.toMutableVertex(): MutableVertex = MutableVertex(id, this, kind, directedEdges.toMutableList())

fun Vertex.toMutableVec3() = MutableVec3(x, y, z)


